<?php

namespace Admin\Controller;

use Common\Controller\AdminbaseController;

class HomesysController extends AdminbaseController {
    public function index() {
 
        $p=1;
        if (isset($_GET['p'])){
            $p=$_GET['p'];
        }
        $queryDesc='order by id';
        
        $postData=array();
        $where='';
        $postData['p']=$p;

        $Model = M();
        $query=$Model->query("SELECT count(id) as count FROM `zhi_supplier` ".$where."  ");
        $count=$query[0]['count'];
        $page = $this->page($count, 10, $p);
        $uInfo=$Model->query("SELECT * FROM `zhi_supplier` ".$where."  ".$queryDesc." limit ".(($p-1)*10).",10 ");
        $theData=array();
        $skillType=array(1=>'设计',2=>'摄制',3=>'文案',21=>'综合');
        foreach ($uInfo as $v){
            
            
            $theData[]=array('id'=>$v['id'],'title'=>$v['title'], 'photo'=>$v['photo'],
                'subtitle'=>$v['subtitle'],'star'=>$v['star'],'price'=>$v['price'],'paixu'=>$v['paixu'],
                'skill_type'=>$skillType[$v['skill_type']],
                'createtime'=>$v['createtime']
            );
        }
        $this->assign("postData", $postData);
        $this->assign("page", $page->show('Admin'));
        $this->assign("thedata", $theData);

        $this->display();
    }
  
    public function edit() {
        if (isset($_GET['id'])){
            $id=$_GET['id'];
        }else{
            exit;
        }
        $p=1;
        if (isset($_GET['p'])){
            $p=$_GET['p'];
        }
        $Model = M();
        $dataInfo=$Model->query("SELECT * FROM `zhi_supplier` where id='".$id."' limit 0,1  ");
        $this->assign("p", $p);
        $this->assign("dataInfo", $dataInfo[0]);
         
        $this->display();
    }
    
    public function add() {
         
        
        $this->display();
    }
    
    public function add_post() {
        if (isset($_POST['title']) && !empty($_POST['title'])){
            $Model = M("supplier", 'zhi_');
            $data=array();
            $data['title'] = addslashes(trim($_POST['title']));
            $data['subtitle'] = addslashes(trim($_POST['subtitle']));
            $data['workyear'] = addslashes(trim($_POST['workyear']));
            $data['sanchang'] = addslashes(trim($_POST['sanchang']));
            $data['jieshao'] = addslashes(trim($_POST['jieshao']));
            $data['lvli'] = addslashes(trim($_POST['lvli']));
            $data['skill_type'] = addslashes(trim($_POST['skill_type']));
            
            
            $data['photo'] = $_POST['smeta']['thumb'];
            $data['star'] = addslashes(trim($_POST['star']));
            $data['price'] = addslashes(trim($_POST['price']));
            $data['paixu'] = addslashes(trim($_POST['paixu']));
            $data['createtime'] = date("Y-m-d H:i:s");
            
            $Model->add($data);
            $info=json_encode(array('status'=>'success'));
            echo $info;
        }
    }
     
    public function editpost() {
 
        if (isset($_POST['title']) && isset($_POST['option_id'])){
            $Model = M("supplier", 'zhi_');
             
            $data=array();
            $data['title'] = addslashes(trim($_POST['title']));
            $data['subtitle'] = addslashes(trim($_POST['subtitle']));
            $data['workyear'] = addslashes(trim($_POST['workyear']));
            $data['sanchang'] = addslashes(trim($_POST['sanchang']));
            $data['jieshao'] = addslashes(trim($_POST['jieshao']));
            $data['lvli'] = addslashes(trim($_POST['lvli']));
            $data['photo'] = $_POST['photo'];
            $data['skill_type'] = addslashes(trim($_POST['skill_type']));
            $data['star'] = addslashes(trim($_POST['star']));
            $data['price'] = addslashes(trim($_POST['price']));
            $data['paixu'] = addslashes(trim($_POST['paixu']));
            $data['createtime'] = date("Y-m-d H:i:s");
            $id=$_POST['option_id'];
            $Model->where('id='.$id)->save($data);
            
            $info=json_encode(array('status'=>'yes'));
            echo $info;
        }
    }
 
}
